package org.example.dayu521;

public enum OrderState {
    //关系是这样的
    // Created -> Payed -> Refund
    // Created -> Cancel -> canceled
    // Created -> Cancel -> Payed
    // Created -> Canceled
    // Created -> Timeout

    //没有创建时也用一个状态表示
    NotFound("NotFound"),
    Created("Created"),Payed("Payed"),Refund("Refund"),Cancel("Cancel"),Timeout("Timeout"),Canceled("Canceled");
    private String value;

    OrderState(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static boolean definite_state(OrderState state){
        return switch (state){
            case NotFound,Created,Cancel -> false;
            default -> true;
        };
    }
    public static boolean definite_state(String state){
        return definite_state(OrderState.valueOf(state));
    }

    public static boolean can_timeout(OrderState state){
        return switch (state){
            case Created ,NotFound,Cancel-> true;
            default -> false;
        };
    }
}
